package com.hb.job;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @projectName: zhb-frame-build
 * @author: zhouhaizhi
 * @createTime: 2021/9/3 11:22
 * @version:1.0
 */
@Slf4j
@Component
public class TestJobHandler {

    private static final String FLAG_PARAM = "flag";

    @XxlJob("testJobHandler")
    public void execute() throws Exception {
        String jobParam = XxlJobHelper.getJobParam();
        log.info("测试调度任务，参数：{}", jobParam);
        Map<String, String> paramMap = CollectionUtil.newHashMap();
        try {
            paramMap = JSON.parseObject(jobParam, HashMap.class);
            if (paramMap.containsKey(FLAG_PARAM)) {
                if (paramMap.get(FLAG_PARAM).equals("1")) {
                    log.info("测试调度任务，有参打印");
                }
                log.info("测试调度任务，业务正在进行中......");
            }
        } catch (Exception e) {
            log.warn("测试调度任务，转换参数异常", e);
            XxlJobHelper.handleFail();
        }

        log.info("测试调度任务，结束！");
    }

}
